---@diagnostic disable: lowercase-global, undefined-global, trailing-space

---@type data_componentaction[]
local data = {
    {
        id = 'ACTION_BH_MOBIUS_LVLUP',
        str = STRINGS.MOD_AVATAR_BH_MOBIUS.ACTIONS.ACTION_BH_MOBIUS_LVLUP,
        fn = function (act)
            local item = act.invobject
            local weapon = act.target
            if item and weapon and item:IsValid() and weapon:IsValid() and weapon.components.bh_mobius_sword_lvlup and item.prefab then
                weapon.components.bh_mobius_sword_lvlup:AddItem(item.prefab)
                S_BH_MOBIUS:consumeOneItem(item)
                return true
            end
            return false
        end,
        state = "give",
        actiondata = {
            mount_valid = true,
            priority = 6,
        },
        type = 'USEITEM',
        component = 'inventoryitem',
        ---comment
        ---@param inst ent
        ---@param doer ent
        ---@param target ent
        ---@param actions any
        ---@param right any
        testfn = function (inst, doer, target, actions, right)
            if inst and inst.prefab and target and target.replica.bh_mobius_sword_lvlup then
                local prefab = inst.prefab
                if TUNING.MOD_AVATAR_BH_MOBIUS.weapon.bh_mobius_sword.lvlup[prefab] then
                    if not target.replica.bh_mobius_sword_lvlup:IsMax(prefab) then
                        return true
                    end
                end
            end
            return false
        end
    },
    -- {
    --     id = 'ACTION_BH_MOBIUS_SWORD_LEAP',
    --     str = STRINGS.MOD_AVATAR_BH_MOBIUS.ACTIONS.ACTION_BH_MOBIUS_SWORD_LEAP,
    --     fn = function (act)
    --         return true
    --     end,
    --     state = 'bh_mobius_sword_leap',
    --     actiondata = {
    --         mount_valid = false,
    --         distance = TUNING.MOD_AVATAR_BH_MOBIUS.weapon.bh_mobius_sword.leap.distance,
    --         priority = 6,
    --     },
    --     type = 'POINT',
    --     component = 'bh_mobius_sword_leap',
    --     testfn = function (inst, doer, pos, actions, right)
    --         return true
    --     end
    -- }
    {
        id = 'ACTION_BH_MOBIUS_SWORD_LEAP',
        str = STRINGS.MOD_AVATAR_BH_MOBIUS.ACTIONS.ACTION_BH_MOBIUS_SWORD_LEAP,
        fn = function (act)
            local weapon = act.invobject
            if weapon and weapon:IsValid() then
                weapon:AddTag('bh_mobius_sword_leap_circle')
                return true
            end
            return false
        end,
        state = "quickcastspell",
        actiondata = {
            mount_valid = false,
            distance = 999,
            priority = 6,
        },
        type = 'POINT',
        component = 'bh_mobius_sword_leap',
        testfn = function (inst, doer, pos, actions, right)
            return right and not inst:HasTag('bh_mobius_sword'..'_iscd') and not inst:HasTag('bh_mobius_sword_leap_circle')
        end
    },
    {
        id = 'ACTION_BH_MOBIUS_SWORD_LEAP_CONFIRM',
        str = STRINGS.MOD_AVATAR_BH_MOBIUS.ACTIONS.ACTION_BH_MOBIUS_SWORD_LEAP_CONFIRM,
        fn = function (act)
            local weapon = act.invobject
            if weapon and weapon:IsValid() and weapon.components.rechargeable then
                weapon:RemoveTag('bh_mobius_sword_leap_circle')
                weapon.components.rechargeable:Discharge(TUNING.MOD_AVATAR_BH_MOBIUS.weapon.bh_mobius_sword.leap.cd)
                S_BH_MOBIUS:declare('跳劈')
                return true
            end
            return false
        end,
        state = "bh_mobius_sword_leap",
        actiondata = {
            mount_valid = false,
            distance = TUNING.MOD_AVATAR_BH_MOBIUS.weapon.bh_mobius_sword.leap.distance,
            priority = 6,
        },
        type = 'POINT',
        component = 'bh_mobius_sword_leap',
        ---comment
        ---@param inst ent
        ---@param doer ent
        ---@param pos any
        ---@param actions any
        ---@param right any
        ---@return boolean
        testfn = function (inst, doer, pos, actions, right)
            if not right then
                if inst:HasTag('bh_mobius_sword_leap_circle') then
                    local x,y,z = ConsoleWorldPosition():Get()
                    if inst.bh_mobius_sword_leap_circle == nil or not inst.bh_mobius_sword_leap_circle:IsValid() then
                        inst.bh_mobius_sword_leap_circle = SpawnPrefab('reticuleaoesmallhostiletarget')
                    end
                    if inst.bh_mobius_sword_leap_circle and inst.bh_mobius_sword_leap_circle:IsValid() then
                        inst.bh_mobius_sword_leap_circle.Transform:SetPosition(x,y,z)
                    end
                    return true
                else
                    if inst.bh_mobius_sword_leap_circle and inst.bh_mobius_sword_leap_circle:IsValid() then
                        inst.bh_mobius_sword_leap_circle:Remove()
                        inst.bh_mobius_sword_leap_circle = nil
                    end
                end
            end
            return false
        end
    },
    {
        id = 'ACTION_BH_MOBIUS_SWORD_LEAP_CANCEL',
        str = STRINGS.MOD_AVATAR_BH_MOBIUS.ACTIONS.ACTION_BH_MOBIUS_SWORD_LEAP_CANCEL,
        fn = function (act)
            local weapon = act.invobject
            if weapon and weapon:IsValid() then
                weapon:RemoveTag('bh_mobius_sword_leap_circle')
                return true
            end
            return false
        end,
        state = "quickcastspell",
        actiondata = {
            mount_valid = false,
            distance = 999,
            priority = 6,
        },
        type = 'POINT',
        component = 'bh_mobius_sword_leap',
        testfn = function (inst, doer, pos, actions, right)
            if right then
                if inst:HasTag('bh_mobius_sword_leap_circle') then
                    return true
                end
            end
            return false
        end
    },
}

---@type data_componentaction_change[]
local change = {

}

return data,change